home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 2003 August / MW 8 2003 CD1.iso / Inside Macworld / Product News / gimp-1.2.4.sit / gimp-1.2.4 / plug-ins / perl / UI / basewidget.pm next >
Encoding:
Perl POD Document  |  2003-01-14  |  2.1 KB  |  107 lines

  1. package Gimp::basewidget; # pragma
  2.  
  3. use Gtk;
  4. use Gimp;
  5.  
  6. $VERSION = 1.211;
  7.  
  8. =head1 NAME
  9.  
  10. Gimp::basewidget - pragma to declare the superclass of a gtk widget
  11.  
  12. =head1 SYNOPSIS
  13.  
  14.   use Gimp::basewidget 'superclass';
  15.  
  16. e.g.
  17.  
  18.   use Gimp::basewidget Gtk::Button;
  19.  
  20. =head1 DESCRIPTION
  21.  
  22. This pragma can (but does not need to) be used to declare the current
  23. package as a childclass of an existing Gtk widget class. The only "import
  24. tag" must be the name of the existing superclass.
  25.  
  26. The module automatically registers a subtype, calls a special callback
  27. at gtk initialization time and provides default implementations for some
  28. common methods (the list might grow in the future to enhance settor/gettor
  29. functionality).
  30.  
  31. The following methods are provided. All of them can be overriden in your
  32. package.
  33.  
  34. =over 4
  35.  
  36. =item new
  37.  
  38. A simple generic new constructor is provided. It will simply call
  39. C<Gtk::Object::new> with all the provided arguments.
  40.  
  41. =item GTK_INIT
  42.  
  43. This callback is called as early as possible I<after> gtk was initialized,
  44. but not before. This can be used to register additional subtypes, argument
  45. types etc. It is similar to GTK_CLASS_INIT.
  46.  
  47. =item GTK_CLASS_INIT
  48.  
  49. Unlike the standard Gtk-callback of the same name, this method can be
  50. omitted in your package (while still being a valid Widget).
  51.  
  52. =item GTK_OBJECT_INIT
  53.  
  54. This callback can also be omitted, but this rarely makes sense ;)
  55.  
  56. =back
  57.  
  58. =cut
  59.  
  60. # a generic perl widget helper class, or something that
  61. # was a pain to implement "right". :(
  62.  
  63. sub GTK_INIT {
  64.    # dummy function, maybe even totally superfluous
  65. }
  66.  
  67. sub GTK_CLASS_INIT {
  68.    # dummy function
  69. }
  70.  
  71. sub GTK_OBJECT_INIT {
  72.    # dummy function, should be overriden
  73. }
  74.  
  75. sub DESTROY {
  76.    # dummy function, very necessary
  77. }
  78.  
  79. *new = \&Gtk::Object::new;
  80.  
  81. sub import {
  82.    my $self  = shift;
  83.    my $super = shift;
  84.    my $class = caller;
  85.    push @{$class."::ISA"}, $self, $super;
  86.    Gimp::gtk_init_hook {
  87.       $class->GTK_INIT;
  88.       Gtk::Object::register_subtype($super,$class);
  89.    };
  90. }
  91.  
  92. 1;
  93.  
  94. =head1 BUGS
  95.  
  96. This was a pain to implement, you will not believe this when looking at
  97. the code, though.
  98.  
  99. =head1 AUTHOR
  100.  
  101. Marc Lehmann <pcg@goof.com>.
  102.  
  103. =head1 SEE ALSO
  104.  
  105. perl(1), L<Gimp>, L<Gimp::UI>, L<Gtk>.
  106.  
  107.